package com.bsoft.controller.JSON;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.bsoft.Exception.CommonException;
import com.bsoft.service.InvoicingBoozService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

@Controller
@RequestMapping
public class InvoicingBoozController {
    private static Logger logger = LoggerFactory.getLogger(HivPushController.class);
    @Autowired
    private InvoicingBoozService invoicingBoozService;

    /**
     * 博思开发票
     */
    @RequestMapping(value = "BS_E_TicketsInvoicing", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String BS_E_TicketsInvoicing(@RequestBody Map<String, Object> req) throws CommonException {
        logger.info("博思开发票:入参：" + req);
        String res = invoicingBoozService.BS_E_TicketsInvoicing(req);
        logger.info("博思开发票:出参" + res);
        return res;
    }

    /**
     * 博思票据冲红 FlushRed
     */
    @RequestMapping(value = "BS_E_TicketsFlushRed", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String BS_E_TicketsFlushRed(@RequestBody Map<String, Object> req) throws CommonException {
        logger.info("博思票据冲红:入参：" + req);
        String res = invoicingBoozService.BS_E_TicketsFlushRed(req);
        logger.info("博思票据冲红:出参" + res);
        return res;
    }


    /**
     * 根据机构 和 发票号码 查询开票信息 或者 已经开票信息
     */
    @RequestMapping(value = "queryInvoiceById", produces = "application/json;charset=utf-8", method = RequestMethod.POST)
    @ResponseBody
    public String queryInvoiceById(@RequestBody Map<String, Object> req) throws CommonException {
        logger.info("电子发票查询:入参：" + JSONUtil.parseObj(req));
        String res = invoicingBoozService.queryInvoiceById(req);
        logger.info("电子发票查询:出参" + res);
        return res;
    }

    /**Get请求参数接收  @RequestParam Map<String, Object> req
     * 获取机构信息
     */
    @RequestMapping(value = "queryHospitalList",method = RequestMethod.GET)
    @ResponseBody
    public String queryHospitalList(@RequestParam Map<String, Object> req) throws CommonException {
        logger.info("获取机构信息:入参：" + JSONUtil.parseObj(req));
        String res = invoicingBoozService.queryHospitalList(req);
        logger.info("获取机构信息:出参" + res);
        return res;
    }

    /*获取就诊产生的发票信息*/
    @RequestMapping(value = "queryVisInfoById",method = RequestMethod.POST)
    @ResponseBody
    public String queryVisInfoById(@RequestBody Map<String, Object> req) throws Exception {
        logger.info("获取就诊产生的发票信息:入参：" + JSONUtil.parseObj(req));
        String res = invoicingBoozService.queryVisInfoById(req);
        logger.info("获取就诊产生的发票信息:出参" + res);
        return res;
    }

    /*将电子发票信息上传医保局*/
    @RequestMapping(value = "uplodMedica",method = RequestMethod.POST)
    @ResponseBody
    public String uplodMedica(@RequestBody Map<String, Object> req) throws Exception {
        logger.info("将电子发票信息上传医保局:入参：" + JSONUtil.parseObj(req));
        String res = invoicingBoozService.uplodMedica(req);
        logger.info("将电子发票信息上传医保局:出参" + res);
        return res;
    }
}
